//package com.fr.hotel.price;
//
//import java.io.IOException;
//
//import org.apache.http.HttpHost;
//import org.elasticsearch.action.admin.indices.alias.Alias;
//import org.elasticsearch.client.RequestOptions;
//import org.elasticsearch.client.RestClient;
//import org.elasticsearch.client.RestHighLevelClient;
//import org.elasticsearch.client.indices.CreateIndexRequest;
//import org.elasticsearch.client.indices.CreateIndexResponse;
//import org.elasticsearch.common.settings.Settings;
//import org.elasticsearch.common.xcontent.XContentBuilder;
//import org.elasticsearch.common.xcontent.XContentFactory;
//
//
///**
// * @author 付荣
// * @version 创建时间：2019年8月9日 下午1:36:30
// */
//public class TestAAA {
//    private static RestHighLevelClient client = new RestHighLevelClient(
//        RestClient.builder(
//                new HttpHost("localhost", 9200, "http"),
//                new HttpHost("localhost", 9201, "http")));
//
//    public static void main(String[] args) {
//        createIndex();
//        try {
//            client.close();
//        } catch (IOException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }
//    }
//    
//    
//    private static void createIndex(){
//        CreateIndexRequest request = new CreateIndexRequest("hotelPrice_20190809"); 
//        request.settings(Settings.builder() 
//            .put("index.number_of_shards", 1)
//            .put("index.number_of_replicas", 0)
//        );
//        request.alias(new Alias("hotelPrice"));
//        XContentBuilder mapping;
//        try {
//            mapping = XContentFactory.jsonBuilder();
//            mapping.startObject();
//            mapping.startObject("_all").field("enabled", false).endObject(); // 禁用 _all
//            mapping.startObject("properties");
//            mapping.startObject("productId").field("type", "log").endObject();
//            mapping.startObject("beginDate").field("type", "string").field("index", "not_analyzed").endObject();
//            mapping.startObject("endDate").field("type", "string").field("index", "not_analyzed").endObject();
//            mapping.startObject("price").field("type", "double").endObject();
//            mapping.endObject().endObject();
//            request.mapping(mapping);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        try {
//            CreateIndexResponse response = client.indices().create(request, RequestOptions.DEFAULT);
//            if(response.isAcknowledged()){
//                System.out.println("创建成功");
//            }
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
//}
